package util;

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class JSFUtil {

	public static ExternalContext getExternalContext() {
		return getContext().getExternalContext();
	}

	public static FacesContext getContext() {
		return FacesContext.getCurrentInstance();
	}

	public static HttpServletRequest getRequest() {
		return (HttpServletRequest) getExternalContext().getRequest();
	}

	public static HttpSession getSession() {
		return getRequest().getSession();
	}
	
	public static void forward(String uri) throws IOException {
		FacesContext context = getContext();
		context.getApplication()
				.getNavigationHandler()
				.handleNavigation(context, null, uri);
	}
	
	public static void addMensagem(String msg) {
		getContext().addMessage(null, new FacesMessage(msg));
	}

}
